]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Append new icons at the first available page after first
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 25 Jun 2020 20:33:48 +0000 (17:33 -0300)
committerFlorian Müllner <florian.muellner@gmail.com>
Mon, 20 Jul 2020 16:13:20 +0000 (16:13 +0000)
As per design discussion, the first page is a somewhat of a special
page where we really don't want to change anything unless necessary.

Append new icons at the first available slot after the first page.
Make the placeholder icon be appended to the first available page
as well, since it's always used when dragging from folder dialogs.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284

js/ui/appDisplay.js

index fdbfef6779f624ffe922a32c02b0c15a5555cb25..4c8678777b3b9aa51930b00d6f5f02515d8d82e2 100644 (file)
@@ -497,10 +497,27 @@ var BaseAppView = GObject.registerClass({
         return true;
     }
 
+    _findBestPageToAppend(startPage = 1) {
+        for (let i = startPage; i < this._grid.nPages; i++) {
+            const pageItems =
+                this._grid.getItemsAtPage(i).filter(c => c.visible);
+
+            if (pageItems.length < this._grid.itemsPerPage)
+                return i;
+        }
+
+        return -1;
+    }
+
     _addItem(item, page, position) {
         let itemIndex = 0;
 
         if (this._grid.nPages > 0) {
+            // Append icons to the first page with empty slot, starting from
+            // the second page
+            if (this._grid.nPages > 1 && page === -1 && position === -1)
+                page = this._findBestPageToAppend();
+
             const realPage = page === -1 ? this._grid.nPages - 1 : page;
 
             itemIndex = position === -1
@@ -1001,8 +1018,14 @@ class AppDisplay extends BaseAppView {
     }
 
     _getItemPosition(item) {
-        if (item === this._placeholder)
-            return this._grid.getItemPosition(item);
+        if (item === this._placeholder) {
+            let [page, position] = this._grid.getItemPosition(item);
+
+            if (page === -1)
+                page = this._findBestPageToAppend(this._grid.currentPage);
+
+            return [page, position];
+        }
 
         return this._pageManager.getAppPosition(item.id);
     }